# from copy import deepcopy
#
# w = [['1' , '*' , '*' , '*' , '*' , '*' , '*'] ,
# 	 ['2' , '2' , '1' , '*' , '1' , '1' , '1'] ,
# 	 ['1' , '*' , '1' , '1' , '1' , '1' , '*']]
# w_ = []
# for i_ in w:
# 	i_ = deepcopy(i_)
# 	i_.append('*')
# 	i_.insert(0 , '*')
# 	w_.append(i_)
# w_.append(list('*' * 8))
# w_.insert(0 , list('*' * 8))

# 把ow设置成横 12 把 col设置成10
# 屏幕大小650 500 素材大小38x38


# x== 横 col等价于列
class tool:
    def __init__(self, total, x1, y1, x2, y2):
        self.total = total
        x1, x2, y1, y2 = self.index(x1, x2, y1, y2)
        self.x1 = x1
        self.x2 = x2
        self.y1 = y1
        self.y2 = y2
        self.block = self.isblock()  # 是数字 返回True 不是返回False

    def isblock(self, *args):
        if not args:
            if self.total[self.y1][self.x1] == '*' or self.total[self.y2][self.x2] == '*':
                return False
            else:
                return True
        y, x = args
        if self.total[y][x] == '*':
            return False
        else:
            return True

    def instance(self, iterable, what='*'):
        for i in iterable:
            if i != what:
                return False
        return True

    def index(self, x1, x2, y1, y2):
        return x1, x2, y1, y2

    def temp(self):
        return self.x1, self.y1, self.x2, self.y2

    def row(self, *args):  # 修改完成
        if not args:
            x1, y1, x2, y2 = self.temp()
        else:
            y1, x1, y2, x2 = args
        if not self.block:
            return False
        max_ = max((x1, x2))
        min_ = min((x1, x2))
        if x1 == x2 and y1 == y2:
            return False
        if y1 != y2:
            return False
        iterable = self.total[y1][min_ + 1:max_]
        if not self.instance(iterable):
            return False
        return True

    def col(self, *args):  # 修改完成
        if not args:
            x1, y1, x2, y2 = self.temp()
        else:
            y1, x1, y2, x2 = args
        if not self.block:
            return False
        max_ = max((y1, y2))
        min_ = min((y1, y2))
        if x1 == x2 and y1 == y2:
            return False
        if x1 != x2:
            return False
        iterable = []
        for i in range(min_ + 1, max_):
            iterable.append(self.total[i][x1])
        # iterable = self.total[y1][min_ + 1:max_]
        if not self.instance(iterable):
            return False
        return True

    def once(self, *args):
        if not args:
            x1, x2, y1, y2 = self.x1, self.x2, self.y1, self.y2
        else:
            y1, x1, y2, x2 = args
        if x1 == x2 and y1 == y2:
            return False
        ret = False
        if not self.isblock(y2, x1):
            ret = self.col(y1, x1, y2, x1) and self.row(y2, x1, y2, x2)
        if not ret and not self.isblock(y1, x2):
            ret = self.col(y1, x1, y1, x2) and self.row(y1, x2, y2, x2)
        return ret

    def twice(self, total_):
        self.total = total_
        self.x1 += 1
        self.x2 += 1
        self.y1 += 1
        self.y2 += 1
        x1 = self.x1;
        x2 = self.x2;
        y1 = self.y1;
        y2 = self.y2
        if x1 == x2 and y1 == y2:
            return False
        for i in range(len(total_)):
            for j in range(len(total_[0])):
                if i != y1 and i != y2 and j != x1 and j != x2:
                    continue
                if i == y2 and j == x1 or i == y2 and j == x2:
                    continue
                if self.isblock(i, j):
                    continue
                if self.once(y1, x1, i, j) and (
                        self.row(i, j, y2, x2) or self.col(i, j, y2, x2)):
                    return True
                if self.once(i, j, y2, x2) and (
                        self.row(y1, x1, i, j) or self.col(y1, x1, i, j)):
                    return True
        return False

    def main(self, total_):
        if self.row() or self.col() or self.once() or self.twice(total_):
            return True
        else:
            return False

# z = tool(w , 2 , 3 , 1 , 5)
# print(str(z.row()))
# print(str(z.once()))
# print(str(z.twice()))
